/*
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * ChannelListPanel.java
 *
 * Created on Apr 27, 2009, 6:16:36 PM
 */
package hextd.UI;

import hextd.message.MessageChannelList.ChannelInfo;
import hextd.util.colorSelection;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

/**
 *
 * @author hylke
 */
public class ChannelListPanel extends javax.swing.JPanel {

	private ChannelInfo info;
	private boolean selected = false;
	colorSelection colors;

	/** Creates new form ChannelListPanel */
	public ChannelListPanel() {
		initComponents();
	}

	public ChannelListPanel(ChannelInfo info, colorSelection colors) {
		this.colors = colors;
		initComponents();
		setInfo(info);
	}

	public void setInfo(ChannelInfo info) {
		this.info = info;
		jLabelName.setText(info.name);
		if (info.open) {
			jLabelOpen.setText("Open ");
		} else {
			jLabelOpen.setText("Closed ");
		}
		if (info.started) {
			jLabelRunning.setText("Running");
		} else {
			jLabelRunning.setText("-");
		}
		jLabelPlayers.setText("" + info.playerCount);
	}

	public ChannelInfo getInfo() {
		return info;
	}

	public void setSelected(boolean selected) {
		if (this.selected != selected) {
			this.selected = selected;
			if (selected) {
				this.setBorder(new LineBorder(colors.getColorForeGroundPale()));
			} else {
				this.setBorder(new EmptyBorder(1, 1, 1, 1));
			}
		}
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabelName = new javax.swing.JLabel();
        jLabelOpen = new javax.swing.JLabel();
        jLabelPlayers = new javax.swing.JLabel();
        jLabelRunning = new javax.swing.JLabel();

        setBackground(colors.getColorBackGround());
        setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        setForeground(colors.getColorForeGround());
        setLayout(new java.awt.GridBagLayout());

        jLabelName.setBackground(colors.getColorBackGround());
        jLabelName.setForeground(colors.getColorForeGround());
        jLabelName.setText("ChannleName");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0E-6;
        add(jLabelName, gridBagConstraints);

        jLabelOpen.setBackground(colors.getColorBackGround());
        jLabelOpen.setFont(jLabelOpen.getFont().deriveFont(jLabelOpen.getFont().getSize()-2f));
        jLabelOpen.setForeground(colors.getColorForeGround());
        jLabelOpen.setText("O");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
        add(jLabelOpen, gridBagConstraints);

        jLabelPlayers.setBackground(colors.getColorBackGround());
        jLabelPlayers.setFont(jLabelPlayers.getFont().deriveFont(jLabelPlayers.getFont().getSize()-2f));
        jLabelPlayers.setForeground(colors.getColorForeGround());
        jLabelPlayers.setText("#");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        add(jLabelPlayers, gridBagConstraints);

        jLabelRunning.setBackground(colors.getColorBackGround());
        jLabelRunning.setFont(jLabelRunning.getFont().deriveFont(jLabelRunning.getFont().getSize()-2f));
        jLabelRunning.setForeground(colors.getColorForeGround());
        jLabelRunning.setText("R");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        add(jLabelRunning, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabelName;
    private javax.swing.JLabel jLabelOpen;
    private javax.swing.JLabel jLabelPlayers;
    private javax.swing.JLabel jLabelRunning;
    // End of variables declaration//GEN-END:variables
}
